<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\widgets\Breadcrumbs;
use app\modules\clinical\models\Patient;
use app\modules\clinical\models\Check;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '辅助检查';
$this->params['breadcrumbs'][] = ['label' => '临床信息', 'url' => ['/clinical/patient']];
$this->params['breadcrumbs'][] = $this->title;
GLOBAL $rel;
$rel = $pt_rel_list;
?>

<?= Breadcrumbs::widget([
    'homeLink' => ['label' => '医疗管理系统', 'url' => '#'],
    'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>

<div class="check-index">

    <p>
        <?= Html::a('创建辅助检查', ['create'], ['class' => 'btn btn-success']) ?>
    </p>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            [
                'attribute' => '姓名',
                'value' => function($data) {
                    if ($data->rel_id == 0) {
                        return Yii::$app->session->get('pt_name');
                    }

                    $relative = Patient::findOne(['pk_id'=>$data->pt_id]);
                    return $relative->pt_name;
                },
            ],
            [
                'attribute' => '与患者关系',
                'value' => function($data) {
                    GLOBAL $rel;
                    if ($data->rel_id == 0) return '';
                    return Patient::getParams('relation')[$rel[$data->pt_id]];
                },
            ],
            [
                'attribute' => 'ck_type',
                'value' => function($data) {
                    return Check::getParams('check_type')[$data->ck_type];
                },
            ],
            'ck_date',
            [
                'attribute' => 'ck_program',
                'value' => function($data) {
                    return Check::getParams('ck_program')[$data->ck_program];
                },
            ],
            // 'ck_result',
            // 'ck_range',
            'ck_unit',
            'update_name',
            'update_at',

            [
                'class' => 'yii\grid\ActionColumn',
                'buttons' =>[
                    'view' => function($url, $model, $key) {
                        return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', '/clinical/check/view?id='.$key);
                    },
                    'update' => function($url, $model, $key) {
                        return Html::a('<span class="glyphicon glyphicon-pencil"></span>', '/clinical/check/update?id='.$key);
                    },
                ],
                'template' => '{view} {update}',
            ],
        ],
    ]); ?>

</div>
